/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: VolatileAtomicTest
 * Author:   AEO WUGUOZHI
 * Date:     2021/3/8 22:54
 * Description: 高并发volatile关键字的原子性（volatile不保证原子性）
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bnuz;

import java.util.Vector;

/**
 * 〈一句话功能简述〉<br> 
 * 〈高并发volatile关键字的原子性（volatile不保证原子性）〉
 *
 * @author AEO WUGUOZHI
 * @create 2021/3/8
 * @since 1.0.0
 */
public class VolatileAtomicTest {

    public static volatile int num = 0;

    public static synchronized void increase(){
        num++;
    }

    public static void main(String[] args) throws InterruptedException{
        Thread[] threads = new Thread[10];
        for(int i = 0;i < threads.length;i++){
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for(int i = 0;i < 1000;i++){
                        increase();

                    }
                }
            });
            threads[i].start();
        }

        for(Thread t:threads){
            t.join();
        }

        System.out.println(num);
    }
    
}